﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(SimpleElectricalEquipment))]
public class ElevatorBtn : SimpleItem_TowSprite, IElevatorBtn
{
    [SerializeField] private Elevator elevator;
    /// <summary>
    /// -99则为不移动
    /// </summary>
    [SerializeField] private Vector2 target = new Vector2(-99,-99);
    private SimpleElectricalEquipment electricalEquipment;
    
    protected override void Awake()
    {
        base.Awake();
        electricalEquipment=GetComponent<SimpleElectricalEquipment>();
        elevator.elevatorBtns.Add(this);
    }

    public void Off()
    {
        UnActive();
    }

    public override void Interactive()
    {
        if (!(electricalEquipment.isOpen && elevator.isOpen&&!isActive))
            return;
        base.Interactive();
        elevator.MoveTo(target, this);
    }


    private void OnDestroy()
    {
        if (elevator!=null)
        {
            elevator.elevatorBtns.Remove(this);
        }
    }
}
